package com.zy.modules.sys.repo;

import com.zy.modules.sys.dao.BDaoImpl;
import com.zy.modules.sys.entity.SysUserEntity;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>user</p>
 * Created by zhezhiyong@163.com on 2017/7/25.
 */
@Component
public class UserDaoImpl extends BDaoImpl<SysUserEntity> implements UserDao {
    @Override
    public List<String> queryAllPerms(Long userId) {
        String sql = "select m.perms from sys_user_role ur " +
                "LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id " +
                "LEFT JOIN sys_menu m on rm.menu_id = m.menu_id " +
                "where ur.user_id = :userId";
        List<String> result = (List<String>) entityManager.createNativeQuery(sql, List.class).setParameter("userId", userId);
        return result;
    }

    @Override
    public List<Long> queryAllMenuId(Long userId) {
        String sql = "select distinct rm.menu_id from sys_user_role ur " +
                "LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id where ur.user_id = :userId";
        List<Long> result = (List<Long>) entityManager.createNativeQuery(sql, List.class).setParameter("userId", userId);
        return result;
    }

}
